package com.atguigu.order.controller;

import com.atguigu.order.bean.Order;
import com.atguigu.order.properties.OrderProperties;
import com.atguigu.order.service.OrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.cloud.context.config.annotation.RefreshScope;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author: dh
 * @date: 2025-03-22 19:46
 */
//@RefreshScope
@RestController
@RequestMapping("/order")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @Autowired
    private OrderProperties orderProperties;

//    @Value("${order.timeout}")
//    private String orderTimeOut;
//
//    @Value("${order.auto-confirm}")
//    private String orderAutoConfirm;

//    @GetMapping("/config")
//    public String orderConfig() {
//
//        return "order.timeout=" + orderTimeOut + ";" + "order.auto-confirm=" + orderAutoConfirm;
//    }

    @GetMapping("/config")
    public String orderConfig() {

        return "order.timeout=" + orderProperties.getTimeout() + ";" +
                "order.auto-confirm=" + orderProperties.getAutoConfirm() +";" +
                "order.db-url=" + orderProperties.getDbUrl() + ";";
    }

    @GetMapping("/create")
    public Order createOrder(@RequestParam("userId") Long userId, @RequestParam("productId") Long productId) {

        Order order =  orderService.createOrder(userId, productId);
        return order;
    }
}
